home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp® 2.0.1 Tutorial / Chapter 14 / UIconEdit.inc1.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  19.5 KB  |  705 lines  |  [TEXT/MPS ]

  1. {Copyright © 1989 by Apple Computer, Inc.  All rights reserved.}
  2.  
  3.  
  4.  
  5. CONST
  6.     kIconHBits =        32;                            { Number of horizontal bits in a bitmap.}
  7.     kIconVBits =        32;                            { Number of vertical bits in a bitmap.    }
  8.  
  9.     kIconSizeInBytes =    kIconHBits * kIconVBits DIV 8;    { Number of bytes in an bitmap.        }
  10.     kIconSizeInLongs =    kIconSizeInBytes DIV 4;        { Number of long words in a bitmap.        }
  11.     kMaxLong =            kIconSizeInLongs - 1;        { Max. addressable long word in bitmap.    }
  12.     
  13.     
  14.     { Resource identifiers }
  15.     
  16.     kSeedIconId =        1000;                        { Id of the seed icon resource.            }
  17.  
  18.     kIconWindowId =        1000;                        { Id of the icon window 'view' resource.}
  19.     kIconViewId =        1001;                        { Id of the TIconView resource.            }
  20.  
  21.     
  22.     { Constants for TIconView }
  23.  
  24.     kDefaultMagnification =    7;                        { Default icon magnification.            }
  25.     kBorder =                5;                        { Border in which to inset drawing.        }
  26.  
  27.     { Command Numbers }
  28.  
  29.     cZoomIn =            1000;                        { Zoom In menu command.                    }
  30.     cZoomOut =            1001;                        { Zoom Out menu command.                }
  31.     cInvert =            1002;                        { Invert menu command.                    }
  32.     cDrawCommand =         1003;                        { Icon drawing-a mouse tracking command }
  33.  
  34.  
  35.  
  36.  
  37. TYPE
  38.     LongArrayHdl =        ^LongArrayPtr;
  39.     LongArrayPtr =        ^LongArray;
  40.     LongArray =            ARRAY [0..kMaxLong] OF LONGINT;
  41.  
  42.  
  43.  
  44. {-------------------------------------------------------------------------------------------}
  45. {--------------------------------TIconApplication methods-----------------------------------}
  46. {-------------------------------------------------------------------------------------------}
  47.  
  48. PROCEDURE TIconApplication.IIconApplication(iconFileType: OSType);
  49.  
  50. VAR anIconView : TIconView;
  51.  
  52. BEGIN
  53.     IApplication(iconFileType);
  54.     
  55.     if gCreateWithTemplates then begin  { Make sure the linker doesn't strip out view code. }
  56.         New(anIconView);
  57.     end;
  58. END;
  59.  
  60.  
  61.  
  62. {-------------------------------------------------------------------------------------------}
  63.  
  64. FUNCTION  TIconApplication.DoMakeDocument(itsCmdNumber: CmdNumber): TDocument; OVERRIDE;
  65.  
  66. VAR
  67.     anIconDocument:        TIconDocument;
  68.  
  69. BEGIN
  70.     New(anIconDocument);                            { Create a TIconDocument object.        }
  71.     FailNIL(anIconDocument);                        { Make sure we were successful.            }
  72.     anIconDocument.IIconDocument;                    { Initialize it.                        }
  73.  
  74.     DoMakeDocument := anIconDocument;                { Return a reference to the document.    }
  75. END;
  76.     
  77.     
  78.     
  79.     
  80. {-------------------------------------------------------------------------------------------}
  81. {----------------------------------TIconDocument methods------------------------------------}
  82. {-------------------------------------------------------------------------------------------}
  83.  
  84. PROCEDURE TIconDocument.IIconDocument;
  85.  
  86. VAR anIconBitMap : TIconBitMap;
  87.  
  88. BEGIN
  89.     fIconBitMap := NIL;                                { Set this to NIL so that if IDocument    }
  90.                                                     { fails, TIconDocument.Free works okay.    }
  91.  
  92.     IDocument(kFileType,                             { This document's file type.            }
  93.               kSignature,                             { This document's creator.                }
  94.               kUsesDataFork,                         { This document does use the data fork    }
  95.               NOT kUsesRsrcFork,                    { …but doesn't use the resource fork.    }
  96.               NOT kDataOpen,                        { We don't want the data fork kept open    }
  97.               NOT kRsrcOpen);                        { …nor the resource fork.                }
  98.  
  99.     New(anIconBitMap);                                { Allocate a new icon bitmap.            }
  100.     FailNil(anIconBitMap);                            { Fail if we can't allocate the handle.    }
  101.     anIconBitMap.IIconBitMap;                        { Initialize it.                        }
  102.  
  103.     fIconBitMap := anIconBitMap;                    { Store a reference to it in a field.    }
  104. END;
  105.  
  106.  
  107.  
  108. {-------------------------------------------------------------------------------------------}
  109.  
  110. PROCEDURE TIconDocument.DoInitialState; OVERRIDE;
  111.     { This method is called to set the document's data to the "new" state, as when the user    }
  112.     { chooses to open a new document instead of an existing one.  We set the value of the     }
  113.     { document's icon bit map to that of a "seed" icon in our resource file.  That way we     }
  114.     { can the document's initial state simply by changing the "seed" icon resource.            }
  115.  
  116. VAR
  117.     seedIcon:        Handle;
  118.  
  119. BEGIN
  120.     seedIcon := GetIcon(kSeedIconId);                { Get the seed icon resource.            }
  121.     FailNilResource(seedIcon);
  122.     fIconBitMap.SetIconBitMap(seedIcon)
  123. END;
  124.  
  125.  
  126.  
  127. {-------------------------------------------------------------------------------------------}
  128.  
  129. PROCEDURE TIconDocument.Free; OVERRIDE;
  130.     
  131. BEGIN
  132.     FreeIfObject(fIconBitMap);                        { Dispose of the icon object if non-Nil.}
  133.  
  134.     INHERITED Free;
  135. END;
  136.  
  137.  
  138.  
  139. {-------------------------------------------------------------------------------------------}
  140.  
  141. PROCEDURE TIconDocument.DoMakeViews (forPrinting: BOOLEAN); OVERRIDE;
  142.  
  143. VAR
  144.     aWindow:  TWindow;
  145.  
  146. BEGIN
  147.     aWindow := NewTemplateWindow(kIconWindowId, SELF);        { Create the view hierarchy }
  148. END;
  149.  
  150.  
  151.  
  152. {-------------------------------------------------------------------------------------------}
  153.  
  154. PROCEDURE TIconDocument.RedrawViews;
  155.  
  156.     PROCEDURE InvalidateView (aView: TView);
  157.  
  158.     BEGIN
  159.         aView.ForceRedraw;                            { Cause the view to be redrawn.            }
  160.     END;
  161.  
  162. BEGIN
  163.     ForAllViewsDo(InvalidateView);                    { Call InvalidateView on each of         }
  164.                                                     { …the document's views.                }
  165. END;
  166.  
  167.  
  168. {-------------------------------------------------------------------------------------------}
  169.  
  170. PROCEDURE TIconDocument.DoSetupMenus; OVERRIDE;
  171.  
  172. BEGIN
  173.     INHERITED DoSetupMenus;                            { Set up inherited menus.                }
  174.  
  175.     Enable(cInvert, TRUE);                            { The icon can always be inverted.        }
  176. END;
  177.  
  178.  
  179.  
  180. {-------------------------------------------------------------------------------------------}
  181.  
  182. FUNCTION TIconDocument.DoMenuCommand (aCmdNumber: CmdNumber): TCommand; OVERRIDE;
  183.  
  184. VAR
  185.     anInvertCommand:        TInvertCommand;
  186.  
  187. BEGIN
  188.     CASE aCmdNumber OF
  189.         cInvert:
  190.             BEGIN
  191.             New(anInvertCommand);
  192.             FailNIL(anInvertCommand);
  193.             anInvertCommand.IInvertCommand(SELF);
  194.             DoMenuCommand := anInvertCommand;
  195.             END;
  196.         OTHERWISE
  197.             DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
  198.         END;
  199. END;
  200.  
  201.  
  202.  
  203. {-------------------------------------------------------------------------------------------}
  204.  
  205. PROCEDURE TIconDocument.InvertIcon;
  206.  
  207. BEGIN
  208.     fIconBitMap.Invert;                                { Invert the bits of the icon.            }
  209.     RedrawViews;                                    { Make sure all views get redrawn.        }
  210. END;
  211.  
  212.  
  213.     
  214. {-------------------------------------------------------------------------------------------}
  215.  
  216. PROCEDURE TIconDocument.Fields (PROCEDURE DoToField (fieldName: Str255;
  217.                                                    fieldAddr: Ptr;
  218.                                                    fieldType: INTEGER)); OVERRIDE;
  219.  
  220. BEGIN
  221.     DoToField('TIconDocument', NIL, bClass);
  222.     DoToField('fIconBitMap', @fIconBitMap, bObject);
  223.  
  224.     INHERITED Fields(DoToField);
  225. END;
  226.  
  227.  
  228. {-------------------------------------------------------------------------------------------}
  229. {------------------------------------TIconView methods--------------------------------------}
  230. {-------------------------------------------------------------------------------------------}
  231.  
  232.  
  233. PROCEDURE TIconView.IRes (itsDocument: TDocument; itsSuperView: TView; VAR itsParams: Ptr);
  234.  
  235. BEGIN
  236.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  237.  
  238.     fMagnification := kDefaultMagnification;
  239.     fIconDocument := TIconDocument(itsDocument);
  240. END;
  241.  
  242.  
  243.  
  244. {-------------------------------------------------------------------------------------------}
  245.  
  246. PROCEDURE TIconView.CalcMinSize (VAR minSize: VPoint); OVERRIDE;
  247.  
  248. BEGIN
  249.     minSize.h := kIconHBits * fMagnification + kBorder + kBorder;
  250.     minSize.v := kIconVBits * fMagnification + kBorder + kBorder;
  251. END;
  252.  
  253.  
  254.  
  255.  
  256. {-------------------------------------------------------------------------------------------}
  257.  
  258. PROCEDURE TIconView.Draw (area: Rect); OVERRIDE;
  259.  
  260. VAR
  261.     drawingRect:    Rect;
  262.  
  263. BEGIN
  264.     SetRect(drawingRect, kBorder, kBorder,
  265.                          kBorder + (kIconHBits * fMagnification),
  266.                          kBorder + (kIconVBits * fMagnification));
  267.  
  268.     fIconDocument.fIconBitMap.Draw(drawingRect);    
  269. END;
  270.  
  271.  
  272. {-------------------------------------------------------------------------------------------}
  273.  
  274. PROCEDURE TIconView.DrawBit (theBit: Point; turnBitOn: BOOLEAN);
  275.  
  276. VAR
  277.     theRect:        Rect;
  278.     thePattern:        Pattern;
  279.  
  280. BEGIN
  281.     SetRect(theRect,                                { Setup the bit's rect the in edit view.}
  282.             kBorder + theBit.h * fMagnification,
  283.             kBorder + theBit.v * fMagnification,
  284.             kBorder + (theBit.h + 1) * fMagnification,
  285.             kBorder + (theBit.v + 1) * fMagnification);
  286.  
  287.     IF turnBitOn THEN                                { Decide which pattern to use.            }
  288.         thePattern := black
  289.     ELSE
  290.         thePattern := white;
  291.     FillRect(theRect, thePattern);                     { Show the bit in the edit view.        }
  292. END;
  293.  
  294.  
  295.  
  296. {-------------------------------------------------------------------------------------------}
  297.  
  298. PROCEDURE TIconView.DoSetupMenus; OVERRIDE;
  299.  
  300. BEGIN
  301.     INHERITED DoSetupMenus;                            { Set up inherited menus.                }
  302.  
  303.     Enable(cZoomIn, TRUE);                            { Can always zoom in.                    }
  304.     Enable(cZoomOut, fMagnification > 1);            { Can zoom out if not at smallest size.    }
  305. END;
  306.  
  307.  
  308.  
  309. {-------------------------------------------------------------------------------------------}
  310.  
  311. FUNCTION TIconView.DoMenuCommand (aCmdNumber: CmdNumber): TCommand; OVERRIDE;
  312.  
  313. BEGIN
  314.     DoMenuCommand := gNoChanges;                    { Initialize result of DoMenuCommand.    }
  315.  
  316.     CASE aCmdNumber OF                                { Decide if this command is ours…        }
  317.  
  318.         cZoomIn:
  319.             SetMagnification(fMagnification + 2);    { Increase size of each bit by 2 pixels.}
  320.  
  321.         cZoomOut:
  322.             SetMagnification(fMagnification - 2);    { Decrease size of each bit by 2 pixels.}
  323.  
  324.         OTHERWISE                                    { Otherwise, let someone else handle it.}
  325.             DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
  326.     END;
  327. END;
  328.  
  329.  
  330.  
  331. {-------------------------------------------------------------------------------------------}
  332.  
  333. PROCEDURE TIconView.SetMagnification (magnification: INTEGER);
  334.  
  335. BEGIN
  336.     fMagnification := Max(1, magnification);        { Set the new magnification.            }
  337.     AdjustSize;                                        { Magnification affects the view's size.}
  338.     ForceRedraw;                                    { Force the view to be entirely redrawn.}
  339. END;
  340.  
  341.  
  342.  
  343. {-------------------------------------------------------------------------------------------}
  344.  
  345. FUNCTION  TIconView.DoMouseCommand (VAR theMouse: Point; VAR info: EventInfo;
  346.                                     VAR hysteresis: Point): TCommand; OVERRIDE;
  347.  
  348. VAR
  349.     iconBit:            Point;
  350.     aDrawCommand:        TDrawCommand;
  351.  
  352. BEGIN
  353.     IF PointToBit(theMouse, iconBit) THEN BEGIN        { If point is within the icon            }
  354.         New(aDrawCommand);                            { …then make a drawing command.            }
  355.         FailNIL(aDrawCommand);
  356.         aDrawCommand.IDrawCommand(SELF);
  357.         DoMouseCommand := aDrawCommand;
  358.     END ELSE
  359.         DoMouseCommand := gNoChanges;                { …else take no action.                    }
  360. END;
  361.  
  362.  
  363.  
  364. {-------------------------------------------------------------------------------------------}
  365.  
  366. FUNCTION  TIconView.PointToBit (thePoint: Point; VAR iconBit: Point): BOOLEAN;
  367.     { Converts the given mouse point to an icon bit. }
  368.  
  369. BEGIN
  370.     thePoint.h := thePoint.h - kBorder;                { Account for border in the edit view.    }
  371.     thePoint.v := thePoint.v - kBorder;
  372.  
  373.     { Is the mouse is within the edit view's icon… }
  374.     IF (thePoint.h >= 0) & (thePoint.h < kIconHBits * fMagnification) &
  375.        (thePoint.v >= 0) & (thePoint.v < kIconVBits * fMagnification) THEN
  376.  
  377.         BEGIN
  378.         iconBit.h := thePoint.h DIV fMagnification;    { Convert from edit view point            }
  379.         iconBit.v := thePoint.v DIV fMagnification;    { …to icon bit.                            }
  380.         PointToBit := TRUE;
  381.         END
  382.  
  383.     ELSE
  384.  
  385.         PointToBit := FALSE;                        { Point is not within the icon.            }
  386. END;
  387.  
  388.  
  389.  
  390. {-------------------------------------------------------------------------------------------}
  391. PROCEDURE TIconView.Fields (PROCEDURE DoToField (fieldName: Str255;
  392.                                                  fieldAddr: Ptr;
  393.                                                  fieldType: INTEGER)); OVERRIDE;
  394.                                                  
  395. BEGIN
  396.     DoToField('TIconView', NIL, bClass);
  397.     DoToField('fIconDocument', @fIconDocument, bObject);
  398.     DoToField('fMagnification', @fMagnification, bInteger);
  399.     
  400.     INHERITED Fields(DoToFIeld);
  401. END;
  402.  
  403.  
  404.  
  405.  
  406.  
  407. {-------------------------------------------------------------------------------------------}
  408. {----------------------------------TInvertCommand methods-----------------------------------}
  409. {-------------------------------------------------------------------------------------------}
  410.  
  411. PROCEDURE TInvertCommand.IInvertCommand (itsIconDocument: TIconDocument);
  412.  
  413. BEGIN
  414.     ICommand(cInvert, itsIconDocument,                { Initialize the inherited data…        }
  415.              NIL, NIL);                                { …no view or scroller to track.        }
  416.  
  417.     fIconDocument := itsIconDocument;                { Save a reference to the icon document.}
  418. END;
  419.  
  420.  
  421.  
  422. {-------------------------------------------------------------------------------------------}
  423.  
  424. PROCEDURE TInvertCommand.DoIt; OVERRIDE;
  425.  
  426. BEGIN
  427.     fIconDocument.InvertIcon;                        { Invert the document's icon bitmap.    }
  428. END;
  429.  
  430.  
  431.  
  432. {-------------------------------------------------------------------------------------------}
  433.  
  434. PROCEDURE TInvertCommand.UndoIt; OVERRIDE;
  435.  
  436. BEGIN
  437.     fIconDocument.InvertIcon;                        { Uninvert the document's icon bitmap.    }
  438. END;
  439.  
  440.  
  441.  
  442. {-------------------------------------------------------------------------------------------}
  443.  
  444. PROCEDURE TInvertCommand.RedoIt; OVERRIDE;
  445.         
  446. BEGIN
  447.     fIconDocument.InvertIcon;                        { Reinvert the document's icon bitmap.    }
  448. END;
  449.  
  450.  
  451.  
  452.  
  453. {-------------------------------------------------------------------------------------------}
  454. {-----------------------------------TDrawCommand methods------------------------------------}
  455. {-------------------------------------------------------------------------------------------}
  456.  
  457. PROCEDURE TDrawCommand.IDrawCommand (itsIconView: TIconView);
  458.  
  459. BEGIN
  460.     ICommand(cDrawCommand,                            { Initialize the command…                }
  461.              itsIconView.fIconDocument,                { Associate it with a document.            }
  462.              itsIconView,                            { Associate it with a view.                }
  463.              itsIconView.GetScroller(TRUE));        { Associate it with a scroller            }
  464.     fConstrainsMouse := TRUE;                        { Want TrackConstrain called.            }
  465.     fCanUndo := FALSE;                                { Can’t undo drawing yet...                }
  466.  
  467.     fIconView := itsIconView;                        { Set some convenience fields…            }
  468.     fIconDocument := itsIconView.fIconDocument;
  469.     fIconBitMap := fIconDocument.fIconBitMap;        { Get reference to icon being drawn.    }
  470. END;
  471.  
  472.  
  473.  
  474. {-------------------------------------------------------------------------------------------}
  475.  
  476. PROCEDURE TDrawCommand.TrackConstrain(anchorPoint, previousPoint: VPoint;
  477.                                       VAR nextPoint: VPoint); OVERRIDE;
  478.  
  479. BEGIN
  480.     nextPoint.h := Max(Min(nextPoint.h, fIconView.fSize.h - kBorder - 1), kBorder);
  481.     nextPoint.v := Max(Min(nextPoint.v, fIconView.fSize.v - kBorder - 1), kBorder);
  482. END;
  483.  
  484.  
  485.  
  486. {-------------------------------------------------------------------------------------------}
  487.  
  488. PROCEDURE TDrawCommand.TrackFeedback(anchorPoint, nextPoint: VPoint;
  489.                                      turnItOn, mouseDidMove: BOOLEAN); OVERRIDE;
  490.  
  491. BEGIN
  492.     { Overridden to avoid standard feedback. }
  493. END;
  494.  
  495.  
  496.  
  497. {-------------------------------------------------------------------------------------------}
  498.  
  499. FUNCTION  TDrawCommand.TrackMouse(aTrackPhase: TrackPhase;
  500.                                   VAR anchorPoint, previousPoint, nextPoint: VPoint;
  501.                                   mouseDidMove: BOOLEAN): TCommand;
  502.  
  503. VAR
  504.     mousePoint,
  505.     iconBit:            Point;
  506.     dontCare:            BOOLEAN;
  507.  
  508. BEGIN
  509.     IF mouseDidMove THEN BEGIN                        { If mouse moved since last time…        }
  510.  
  511.         { Convert nextPoint, which is in view coordinates (long integers) to mousePoint,       }
  512.         { the same location expressed in QuickDraw coordinates (integers).                       }
  513.         mousePoint := fIconView.ViewToQDPt(nextPoint);
  514.         
  515.         { Convert mousePoint (the point on the screen) to a bit location in the icon…         }
  516.         dontCare := fIconView.PointToBit(mousePoint, iconBit);
  517.  
  518.         { If this is the first time TrackMouse is called, decide whether to turn bits on.      }
  519.         IF aTrackPhase = TrackPress THEN BEGIN                    
  520.             fTurnBitsOn := NOT fIconBitMap.GetBit(iconBit);        
  521.         END;
  522.  
  523.         fIconBitMap.SetBit(iconBit, fTurnBitsOn);        { Set the bit in the icon            }
  524.         fIconView.DrawBit(iconBit, fTurnBitsOn);        { …and draw it in the edit view.    }
  525.     END;
  526.  
  527.     TrackMouse := SELF;                                    { Return the same command object.    }
  528. END;
  529.  
  530.  
  531.  
  532.  
  533. {-------------------------------------------------------------------------------------------}
  534. {-----------------------------------TIconBitMap methods-------------------------------------}
  535. {-------------------------------------------------------------------------------------------}
  536.  
  537. PROCEDURE TIconBitMap.IIconBitMap;
  538.  
  539. BEGIN
  540.     fDataHandle := NewPermHandle(kIconSizeInBytes);    { Allocate a handle for the bitmap.        }
  541.     FailNil(fDataHandle);                            { Fail if we can't allocate the handle.    }
  542. END;
  543.  
  544.  
  545.  
  546. {-------------------------------------------------------------------------------------------}
  547.  
  548. PROCEDURE TIconBitMap.Free; OVERRIDE;
  549.  
  550. BEGIN
  551.     DisposIfHandle(fDataHandle);                    { dispose of icon data.                    }
  552. END;
  553.  
  554.  
  555.  
  556. {-------------------------------------------------------------------------------------------}
  557.  
  558. PROCEDURE TIconBitMap.SetIconBitMap(theBitMap : Handle);
  559.  
  560. BEGIN
  561.     BlockMove(theBitMap^, fDataHandle^,                { …then copy it into the document's     }
  562.                 kIconSizeInBytes)                    { …icon bitmap.                            }
  563. END;
  564.             
  565.             
  566.  
  567. {-------------------------------------------------------------------------------------------}
  568.  
  569. PROCEDURE TIconBitMap.Clear;
  570.  
  571. VAR
  572.     iconAsLongArray:    LongArrayHdl;
  573.     i:                    INTEGER;
  574.  
  575. BEGIN
  576.     iconAsLongArray := LongArrayHdl(fDataHandle);    { Cast to array of longints.            }
  577.  
  578.     FOR i := 0 TO kMaxLong DO                        { Clear the bits 32 at a time.            }
  579.         iconAsLongArray^^[i] := 0;
  580. END;
  581.  
  582.  
  583.  
  584. {-------------------------------------------------------------------------------------------}
  585.  
  586. PROCEDURE TIconBitMap.Invert;
  587.  
  588. VAR
  589.     iconAsLongArray:    LongArrayHdl;
  590.     i:                    INTEGER;
  591.  
  592. BEGIN
  593.     iconAsLongArray := LongArrayHdl(fDataHandle);    { Cast to array of longints.            }
  594.  
  595.     FOR i := 0 TO kMaxLong DO                        { Invert the bits 32 at a time.            }
  596.         iconAsLongArray^^[i] := BNOT(iconAsLongArray^^[i]);
  597. END;
  598.  
  599.  
  600.  
  601. {-------------------------------------------------------------------------------------------}
  602.  
  603. PROCEDURE TIconBitMap.IconBitToWordBit (iconBit: Point; VAR word, bit: INTEGER);
  604.     { This converts the given icon bit to a word and bit in an array of long words. }
  605.  
  606. VAR
  607.     bitNumber:        INTEGER;
  608.  
  609. BEGIN
  610.     bitNumber := iconBit.v * kIconVBits + iconBit.h;
  611.     word := bitNumber DIV 32;
  612.     bit := 31 - (bitNumber MOD 32);
  613. END;
  614.  
  615.  
  616.  
  617. {-------------------------------------------------------------------------------------------}
  618.  
  619. FUNCTION  TIconBitMap.GetBit (iconBit: Point): BOOLEAN;
  620.     { Returns the state of the given bit in the icon being drawn. }
  621.  
  622. VAR
  623.     word:            INTEGER;
  624.     bitInWord:        INTEGER;
  625.  
  626. BEGIN
  627.     IconBitToWordBit(iconBit, word, bitInWord);
  628.  
  629.     GetBit := BTst(LongArrayHdl(fDataHandle)^^[word], bitInWord);
  630. END;
  631.  
  632.  
  633.  
  634. {-------------------------------------------------------------------------------------------}
  635.  
  636. PROCEDURE TIconBitMap.SetBit (iconBit: Point; turnBitOn: BOOLEAN);
  637.     { Set the state of the given bit in the icon being drawn. }
  638.  
  639. VAR
  640.     word:            INTEGER;
  641.     bitInWord:        INTEGER;
  642.  
  643. BEGIN
  644.     IconBitToWordBit(iconBit, word, bitInWord);
  645.  
  646.     {$H-}                                            { So the compiler thinks this is unsafe.}
  647.     IF turnBitOn THEN
  648.         BSet(LongArrayHdl(fDataHandle)^^[word], bitInWord)
  649.     ELSE
  650.         BClr(LongArrayHdl(fDataHandle)^^[word], bitInWord);
  651.     {$H+}
  652. END;
  653.  
  654.  
  655.  
  656. {-------------------------------------------------------------------------------------------}
  657.  
  658. FUNCTION TIconBitMap.Copy: TIconBitMap;
  659.  
  660. VAR
  661.     copyOfIcon:        TIconBitMap;
  662.  
  663. BEGIN
  664.     New(copyOfIcon);                                { Create a TIcon object.                }
  665.     FailNIL(copyOfIcon);                            { Make sure we were successful.            }
  666.     copyOfIcon.IIconBitMap;                            { Initialize it.                        }
  667.     copyOfIcon.SetIconBitMap(fDataHandle);            { Copy the data.                        }
  668.     Copy := copyOfIcon;                                { Return a reference to the new handle.    }
  669. END;
  670.  
  671.  
  672.             
  673. {-------------------------------------------------------------------------------------------}
  674.  
  675. PROCEDURE TIconBitMap.Draw (area: Rect);
  676.  
  677. BEGIN
  678.     PlotIcon(area, fDataHandle);    
  679. END;
  680.  
  681.  
  682.  
  683. {-------------------------------------------------------------------------------------------}
  684.  
  685. PROCEDURE TIconBitMap.CopyDataTo (anIcon: TIconBitMap);
  686.  
  687. BEGIN
  688.     anIcon.SetIconBitMap(fDataHandle);                { Copy data to the new icon.            }
  689. END;
  690.  
  691.  
  692. {-------------------------------------------------------------------------------------------}
  693.  
  694. PROCEDURE TIconBitMap.Fields (PROCEDURE DoToField (fieldName: Str255;
  695.                                                    fieldAddr: Ptr;
  696.                                                    fieldType: INTEGER)); OVERRIDE;
  697.  
  698. BEGIN
  699.     DoToField('TIconBitMap', NIL, bClass);
  700.     DoToField('fDataHandle', @fDataHandle, bHandle);
  701.  
  702.     INHERITED Fields(DoToField);
  703. END;
  704.  
  705.